package com.example.demo.controller;

import com.example.demo.common.convention.result.Result;
import com.example.demo.common.convention.result.Results;
import com.example.demo.dto.request.QrCodeReq;
import com.example.demo.service.QRCodeService;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.async.DeferredResult;



@RestController
@RequestMapping("/api/qrcode")
@RequiredArgsConstructor
@Slf4j
public class QRCodeController {


    final private QRCodeService qrCodeService;


    @GetMapping("/getQRCode")
    public DeferredResult<Object> getQRCode(HttpServletRequest request) {
        String userId = request.getAttribute("userId").toString();
        return qrCodeService.getQRCode(userId);
    }

    @PostMapping("/postQrCode")
    public Result<String> postQrCode(@RequestBody QrCodeReq req){
        log.info(req.toString());
        return Results.success(qrCodeService.postQrCode(req.getUserid(),req.getCode()));
    }

}
